// var online = location.href.indexOf('dream-timegroup.com')!=-1;
// var getDomain = online ? "": "http://t.tab.be-xx.com/Dreamtime/website";
var getDomain = "";
var requestDomain = "/api_20180201";
$(document).ready(function () {
  
});
// AJAX请求的方法
function iAjax(API, data, callback, type) {
  var iType = type || false;
  $.ajax({
    type: 'POST',
    url: requestDomain + API,
    dataType: 'json',
    async: false,
    data: data,
    success: successF,
    error: errorF
  });

  function successF(data) {
    if (iType) {
      if (callback) callback(data);
    }
    else {
      if (data.errcode == 0) {
        if (callback) callback(data.result);
      }
      else {
        fn.alert(data.errmsg)
      }
    }
  }

  function errorF(data) {
    // fn.alert("网络可能存在问题，请刷新试试！");
  }
}//end func

//字符串截取
function setString(str, len) {  //截取字符串长度
  var strlen = 0;
  var s = "";
  for (var i = 0; i < str.length; i++) {
      if (str.charCodeAt(i) > 128) {
          strlen += 2;
      } else {
          strlen++;
      }
      s += str.charAt(i);
      if (strlen >= len) {
          return s+"...";
      }
  }
  return s;
}//end func

//转换时间
function transTime(date){
  if(date){
    date =  new Date(parseInt(date.PublishDate.slice(6, 19)));
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  }
}//end func

//字符串截取
function setString(str, len) {  //截取字符串长度
  var strlen = 0;
  var s = "";
  if(str.length){
    for (var i = 0; i < str.length; i++) {
      if (str.charCodeAt(i) > 128) {
        strlen += 2;
      } else {
        strlen++;
      }
      s += str.charAt(i);
      if (strlen >= len) {
        return s + "......";
      }
    }
    return s;
  }else{
    return false;
  }
  
}//end func

//处理面包屑导航的数据
function dealBreadcrumbsData(data) {
  var cont = "";
  data = data.split(",");
  var title = data.pop();
  cont += '<h1 style="display:none;">' + title + '</h1><ul>';
  for (var i = 0; i < data.length; i++) {
    var item = data[i].split("--");
    if (item[1]) cont += '<a href="' + item[1] + '""><li>' + item[0] + '<span>></span></li></a>';
    else cont += '<li>' + item[0] + '<span>></span></li>';
  };
  cont += '<li class="active">' + title + '</li></ul>';
  $("#Breadcrumbs").append(cont);
}//end func

//改变面包屑导航栏
function changeBreadcrumbs(word, pre) {
  // $("#Breadcrumbs h1").html(word);
  $("#Breadcrumbs li.active").html(word);
  if (pre) {
    var ele = $("#Breadcrumbs li.active").prev();
    if (ele.is('a')) ele.children('li').html(pre + "<span>></span>");
    else if (word == "") {
      $("#Breadcrumbs li.active").remove();
      ele.addClass('active');
      ele.html(pre);
      $("#Breadcrumbs h1").html(pre);
    }
    else ele.html(pre + "<span>></span>");
  }
}//end func

//兼容IE8forEach方法
if (!Array.prototype.forEach) {
  Array.prototype.forEach = function forEach(callback, thisArg) {
    var T, k;
    if (this == null) {
      throw new TypeError("this is null or not defined");
    }
    var O = Object(this);
    var len = O.length >>> 0;
    if (typeof callback !== "function") {
      throw new TypeError(callback + " is not a function");
    }
    if (arguments.length > 1) {
      T = thisArg;
    }
    k = 0;
    while (k < len) {
      var kValue;
      if (k in O) {
        kValue = O[k];
        callback.call(T, kValue, k, O);
      }
      k++;
    }
  };
}

var icom1 = importCom();
function importCom() {
  var com = {};
  //常用正则
  com.checkStr = function (str, type) {
    if (str && str != '') {
      type = type || 0;
      switch (type) {
        case 0:
          var reg = new RegExp(/^1[3-9]\d{9}$/); //手机号码验证
          break;
        case 1:
          var reg = new RegExp(/^[1-9]\d{5}$/); //邮政编码验证
          break;
        case 2:
          var reg = new RegExp(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/); //匹配EMAIL
          break;
        case 3:
          var reg = new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/); //匹配身份证
          break;
        case 4:
          var reg = new RegExp(/^\d+$/); //是否为0-9的数字
          break;
        case 5:
          var reg = new RegExp(/^[a-zA-Z\u0391-\uFFE5]*[\w\u0391-\uFFE5]*$/); //不能以数字或符号开头
          break;
        case 6:
          var reg = new RegExp(/^\w+$/); //匹配由数字、26个英文字母或者下划线组成的字符串
          break;
        case 7:
          var reg = new RegExp(/^[\u0391-\uFFE5]+$/); //匹配中文
          break;
        case 8:
          var reg = new RegExp(/^[a-zA-Z\u0391-\uFFE5]+$/); //不能包含数字和符号
          break;
      } //end switch
      if (reg.exec($.trim(str))) return true;
      else return false;
    } //end if
    else return false;
  } //end func
  return com;
}//end func

//表单
function getFormJson(form) {
  var obj = {};
  var arr = $(form).serializeArray();
  $.each(arr, function () {
    if (obj[this.name] !== undefined) {
      if (!obj[this.name].push) {
        obj[this.name] = [obj[this.name]];
      }
      obj[this.name].push(this.value || '');
    } else {
      obj[this.name] = this.value || '';
    }
  });
  return obj;
}//end func

function getQueryString(name) {
  // 获取参数
  var url = window.location.search;
  // 正则筛选地址栏
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  // 匹配目标参数
  var result = url.substr(1).match(reg);
  //返回参数值
  return result ? decodeURIComponent(result[2]) : null;
}//end func

